<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/2
 * Time: 17:35
 */

namespace app\index\controller;
use think\Controller;
use think\Db;
use think\facade\View;

// 模板操作
class Demo09 extends Controller
{
    public function test1(){
        // 直接将内容输出到页面，不通过模板
        $content = '<h3 style="color:green">PHP是最烂的语言!</h3>';
//        return $this->display($content);
//        return $this->view->display($content);
        return View::display($content); # 还可以使用静态代理
    }

    // 使用视图将数据进行输出: fetch()
    public function test2(){
        $this->view->assign('name','a-ke');
        $this->view->assign('age',40);
        $this->view->assign('info', [
            'email'=>'aaa@bbb.com',
            'mob'=>'13455559999'
        ]);
        $obj = new \app\common\Test();
        $obj->name = '张三';
        $obj->sex = '男';
        $this->view->assign('obj', $obj);

        // 模板默认的目录位于当前模块的view目录
        return $this->view->fetch();
    }

    public function test3(){
        $data = Db::name('mnd_combos')
            ->field('id,zk_combo_title,mnd_combo_title,status,at')
            ->where([
                ['zk_combo_id','>',0]
            ])->select();
        $this->view->assign('data',$data);
        return $this->view->fetch();
    }

    public function test4(){
        // 获取分页要调用查询类中的paginate(num)方法
        // 每页显示5条
        $data = Db::name('mnd_combos')
            ->field('id,zk_combo_title,mnd_combo_title,mnd_combo_area,at')
            ->where([
                ['zk_combo_id','>',0]
            ])->paginate(5);
        $this->view->assign('data',$data);
        return $this->view->fetch();
    }

    public function test5(){
        // 模板继承
        return $this->view->fetch();
    }
}